const puppeteer = require("puppeteer");
const cheerio = require("cheerio");

async function detail(id){
    const browser = await puppeteer.launch({
        defaultViewport:null
    })
    const page = await browser.newPage()
    await page.goto(`https://music.163.com/#/playlist?id=${id}`)
    var iframe = await page.$(".g-iframe")
    var frame = await iframe.contentFrame()
    var content = await frame.content()
    const $ = cheerio.load(content,{
        decodeEntities:false
    })
    var detailData={}
    var coverImage = $(".cover img").attr("src")
    var title = $(".tit h2").html()
    var user = $(".user>a img").attr("src")
    var username = $(".user .name").text()
    var time = $(".user .time").text()
    var add =$(".u-btni-fav i").text() 
    var share = $(".u-btni-share i").text()
    var comment = $("#cnt_comment_count").text()
    var intro = $("#album-desc-more").text()
    var cds = []
    var arr = $("tbody tr")
    arr.each((index,value)=>{
        var num = $(value).find(".hd .num").text()
        var song = $(value).find(".txt a").text()
        var songtime = $(value).find(".s-fc3 .u-dur ").text()
        var singer = $(value).find(".text>span a").text()
        cds.push({
            num,
            song,
            songtime,
            singer
        })
    })
    detailData= {coverImage,title,user,username,time,add,share,comment,intro,cds}
    
    return detailData
}
module.exports = detail